﻿<Window x:Class="HDFSViewer.View.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:gif="http://wpfanimatedgif.codeplex.com"
        xmlns:dock="http://schemas.xceed.com/wpf/xaml/avalondock"
        xmlns:extension="clr-namespace:HDFSViewer.Extension"
        xmlns:model="clr-namespace:HDFSViewer.Model"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:converter="clr-namespace:HDFSViewer.Converter"
        Title="HDFS Viewer" Height="768" Width="1024" WindowStartupLocation="CenterScreen" Icon="Image/Disk.png">

    <Window.Resources>
        <converter:NodeTypeConverter x:Key="ntc"/>
    </Window.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="36"/>
            <RowDefinition Height="1*"/>
            <RowDefinition Height="20"/>
        </Grid.RowDefinitions>
        <ToolBar Grid.Row="0">
            <Menu Width="40">
                <MenuItem>
                    <MenuItem.Icon>
                        <Image Source="Image/Setting.png" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                    </MenuItem.Icon>
                    <MenuItem Header="Apache Hadoop" Command="{Binding Path=ConnectHadoop}"/>
                    <MenuItem Header="Azure HDInsight" Command="{Binding Path=ConnectHDInsight}"/>
                </MenuItem>
            </Menu>
            <Button ToolTip="Disconnect" Command="{Binding Path=Disconnect}">
                <Button.Content>
                    <Image Source="Image/Disconnect.png"></Image>
                </Button.Content>
            </Button>
        </ToolBar>
        <Grid Grid.Row="1">
            <dock:DockingManager>
                <dock:DockingManager.DocumentHeaderTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <Image Source="{Binding IconSource}" Margin="0,0,4,0"/>
                            <TextBlock Text="{Binding Title}" TextTrimming="CharacterEllipsis"/>
                        </StackPanel>
                    </DataTemplate>
                </dock:DockingManager.DocumentHeaderTemplate>
                <dock:LayoutRoot>
                    
                    <dock:LayoutPanel Orientation="Vertical">
                        <dock:LayoutPanel Orientation="Horizontal">
                            <dock:LayoutAnchorablePane DockWidth="300">
                                <dock:LayoutAnchorable Title="Explorer" CanHide="false" CanClose="False">
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="30"/>
                                            <RowDefinition Height="1*"/>
                                        </Grid.RowDefinitions>
                                        <ToolBar Grid.Row="0">
                                            <Button ToolTip="Refresh Directory" Command="{Binding Path=RefreshDirectory}">
                                                <Button.Content>
                                                    <Image Source="Image/Refresh.png" />
                                                </Button.Content>
                                            </Button>
                                            <Button ToolTip="ExpandAll" Command="{Binding Path=ExpandAll}">
                                                <Button.Content>
                                                    <Image Source="SmallImage/ExpandAll.png" />
                                                </Button.Content>
                                            </Button>
                                            <Button ToolTip="CollapseAll" Command="{Binding Path=CollapseAll}">
                                                <Button.Content>
                                                    <Image Source="SmallImage/CollapseAll.png" />
                                                </Button.Content>
                                            </Button>
                                            <Button ToolTip="View File..." Command="{Binding Path=ViewFile}">
                                                <Button.Content>
                                                    <Image Source="SmallImage/View.png" />
                                                </Button.Content>
                                            </Button>
                                            <Button ToolTip="Add Directory..." Command="{Binding Path=AddDirectory}">
                                                <Button.Content>
                                                    <Image Source="SmallImage/AddDirectory.png" />
                                                </Button.Content>
                                            </Button>
                                            <Button ToolTip="Add File..." Command="{Binding Path=AddFile}">
                                                <Button.Content>
                                                    <Image Source="SmallImage/AddFile.png" />
                                                </Button.Content>
                                            </Button>
                                            <Button ToolTip="Append File..." Command="{Binding Path=AppendFile}">
                                                <Button.Content>
                                                    <Image Source="SmallImage/Append.png" />
                                                </Button.Content>
                                            </Button>
                                            <Button ToolTip="Upload File..." Command="{Binding Path=UploadFile}">
                                                <Button.Content>
                                                    <Image Source="SmallImage/Upload.png" />
                                                </Button.Content>
                                            </Button>
                                            <Button ToolTip="Download File..." Command="{Binding Path=DownloadFile}">
                                                <Button.Content>
                                                    <Image Source="SmallImage/Download.png" />
                                                </Button.Content>
                                            </Button>
                                            <Button ToolTip="Delete" Command="{Binding Path=Delete}">
                                                <Button.Content>
                                                    <Image Source="SmallImage/Delete.png" />
                                                </Button.Content>
                                            </Button>
                                        </ToolBar>
                                        <TreeView x:Name="MainTree" Grid.Row="1" ItemsSource="{Binding Path=TreeViewDataContext}" ContextMenuOpening="MainTree_ContextMenuOpening"  extension:TreeViewSelectedItemExtension.TreeViewSelectedItem="{Binding Path=SelectedHDFSNodeModel,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
                                            <TreeView.ItemTemplate>
                                                <HierarchicalDataTemplate DataType="{x:Type model:HDFSNodeModel}" ItemsSource="{Binding Path=Childs}">
                                                    <StackPanel Orientation="Horizontal">
                                                        <Image VerticalAlignment="Center" Source="{Binding Type,Converter={StaticResource ntc}}" Width="16" Height="16" Margin="0,0,2,2"></Image>
                                                        <TextBlock VerticalAlignment="Center" Text="{Binding Name}"></TextBlock>
                                                    </StackPanel>
                                                </HierarchicalDataTemplate>
                                            </TreeView.ItemTemplate>

                                            <TreeView.ItemContainerStyle>
                                                <Style TargetType="TreeViewItem">
                                                    <Setter Property="IsExpanded" Value="{Binding IsExpended, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                                                </Style>
                                            </TreeView.ItemContainerStyle>

                                            <TreeView.ContextMenu>
                                                <ContextMenu>
                                                    <MenuItem Header="Refresh Directory" Command="{Binding Path=RefreshDirectory}">
                                                        <MenuItem.Icon>
                                                            <Image Source="SmallImage/Refresh.png" />
                                                        </MenuItem.Icon>
                                                    </MenuItem>
                                                    <MenuItem Header="ExpandAll" Command="{Binding Path=ExpandAll}">
                                                        <MenuItem.Icon>
                                                            <Image Source="SmallImage/ExpandAll.png" />
                                                        </MenuItem.Icon>
                                                    </MenuItem>
                                                    <MenuItem Header="CollapseAll" Command="{Binding Path=CollapseAll}">
                                                        <MenuItem.Icon>
                                                            <Image Source="SmallImage/CollapseAll.png" />
                                                        </MenuItem.Icon>
                                                    </MenuItem>
                                                    <MenuItem Header="View File..." Command="{Binding Path=ViewFile}">
                                                        <MenuItem.Icon>
                                                            <Image Source="SmallImage/View.png" />
                                                        </MenuItem.Icon>
                                                    </MenuItem>
                                                    <MenuItem Header="Add Directory..." Command="{Binding Path=AddDirectory}">
                                                        <MenuItem.Icon>
                                                            <Image Source="SmallImage/AddDirectory.png" />
                                                        </MenuItem.Icon>
                                                    </MenuItem>
                                                    <MenuItem Header="Add File..." Command="{Binding Path=AddFile}">
                                                        <MenuItem.Icon>
                                                            <Image Source="SmallImage/AddFile.png" />
                                                        </MenuItem.Icon>
                                                    </MenuItem>
                                                    <MenuItem Header="Append File..." Command="{Binding Path=AppendFile}">
                                                        <MenuItem.Icon>
                                                            <Image Source="SmallImage/Append.png" />
                                                        </MenuItem.Icon>
                                                    </MenuItem>
                                                    <MenuItem Header="Upload File..." Command="{Binding Path=UploadFile}">
                                                        <MenuItem.Icon>
                                                            <Image Source="SmallImage/Upload.png" />
                                                        </MenuItem.Icon>
                                                    </MenuItem>
                                                    <MenuItem Header="Download File..." Command="{Binding Path=DownloadFile}">
                                                        <MenuItem.Icon>
                                                            <Image Source="SmallImage/Download.png" />
                                                        </MenuItem.Icon>
                                                    </MenuItem>
                                                    <MenuItem Header="Delete" Command="{Binding Path=Delete}">
                                                        <MenuItem.Icon>
                                                            <Image Source="SmallImage/Delete.png" />
                                                        </MenuItem.Icon>
                                                    </MenuItem>
                                                </ContextMenu>
                                            </TreeView.ContextMenu>
                                        </TreeView>
                                    </Grid>
                                </dock:LayoutAnchorable>
                            </dock:LayoutAnchorablePane>
                            <dock:LayoutDocumentPaneGroup>
                                <dock:LayoutDocumentPane x:Name="ldpMain">
                                </dock:LayoutDocumentPane>
                            </dock:LayoutDocumentPaneGroup>
                        </dock:LayoutPanel>

                        <dock:LayoutAnchorablePane DockHeight="150">
                            <dock:LayoutAnchorable Title="Log" CanHide="false" CanClose="False" >
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="30"/>
                                        <RowDefinition Height="1*"/>
                                    </Grid.RowDefinitions>
                                    <ToolBar Grid.Row="0">
                                        <Button ToolTip="Clear Log" Command="{Binding Path=ClearLog}">
                                            <Button.Content>
                                                <Image Source="Image/Clear.png"></Image>
                                            </Button.Content>
                                        </Button>
                                    </ToolBar>
                                    <ListBox x:Name="lbLog" Grid.Row="1" ItemsSource="{Binding Path=LogContext}" SelectedValue="{Binding Path=SelectedLog}">
                                        <ListBox.ItemTemplate>
                                            <DataTemplate DataType="{x:Type model:OperationLogModel}">
                                                <Grid>
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="16"/>
                                                        <ColumnDefinition Width="150"/>
                                                        <ColumnDefinition Width="*"/>
                                                    </Grid.ColumnDefinitions>

                                                    <Image Grid.Column="0" gif:ImageBehavior.AnimatedSource="{Binding Path=Status}"/>
                                                    <TextBlock Grid.Column="1" VerticalAlignment="Center" Text="{Binding Path=Type}"/>
                                                    <TextBlock Grid.Column="2" VerticalAlignment="Center" Text="{Binding Path=Message}"/>

                                                </Grid>
                                            </DataTemplate>
                                        </ListBox.ItemTemplate>
                                    </ListBox>
                                </Grid>
                            </dock:LayoutAnchorable>
                        </dock:LayoutAnchorablePane>

                    </dock:LayoutPanel>
                </dock:LayoutRoot>
            </dock:DockingManager>
        </Grid>
        <StatusBar Grid.Row="2"/>
    </Grid>
</Window>
